<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ejecucion por fondo</title>
<link href="estilacho.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:link {
	color: #993300;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #993300;
}
a:hover {
	text-decoration: none;
	color: #993300;
}
a:active {
	text-decoration: none;
	color: #FF0000;
}
-->
</style></head>

<body>
  <?
include 'conexion.php';
  extract($_POST);
    extract($_GET);
 /* $base= "ucg - copia";
	$conexion = mysql_connect("localhost","root","");
	mysql_select_db($base,$conexion); */

	$sqlf=mysql_query("Select sum(monto) from fondo where fondo='".$fondo."' AND ano='$ano'",$conexion);
	 $regf= mysql_fetch_array($sqlf);


	?>
<table border="0" class="tablainstitucion" align="center">
  <th colspan="2"> Ejecucion por fondo </th>
  <tr>

    <td width="36%" >Fondo de Anticipo N&ordm;:&nbsp;  <? echo "$fondo";?> </td>
    <td width="25%" >Asignaci&oacute;n del Fondo:&nbsp;  <?
	  $pres=$regf[0];
	  $pres2= number_format($regf[0],2,",",".");
	  echo $pres2;?> Bs.</td>

  </tr></table>
<!--<p>
  </p>-->
    <table border="1" class="tablainstitucion" align="center" >
    <tr>
      <td width="32" align="center" bordercolor="#000000"><span class="Estilo32">Fecha</span></td>
      <td width="141" align="center" bordercolor="#000000"><span class="Estilo32">Descripci&oacute;n</span></td>
      <td width="44" align="center" bordercolor="#000000"><span class="Estilo32">N&ordm; de Cheque </span></td>
      <td width="150" align="center" bordercolor="#000000"><span class="Estilo32">Nombre de la Cuenta perteneciente a este Fondo</span></td>
      <td width="62" align="center" bordercolor="#000000"><span class="Estilo32">Monto por Partida </span></td>
      <td width="37" align="center" bordercolor="#000000"><span class="Estilo32">Pagado</span></td>
      <td width="35" align="center" bordercolor="#000000"><span class="Estilo32">Saldo Financiero</span></td>
      <td width="35" align="center" bordercolor="#000000">% de Ejecucion</td>
    </tr> 
 <?
/*Muestra fondo de anticipo un valor que no corresponde al igual q la orden de pago
 *
 */
 $sql8=mysql_query("Select * from fondo where fondo='".$fondo."' AND ano='$ano'",$conexion);

	 $reg8= mysql_fetch_array($sql8); ?>
		    <tr>
		      <td bordercolor="#000000"><? echo $reg8[2] ?></td>
		      <td bordercolor="#000000">Fondo de Anticipo N&ordm; <? echo $reg8[0] ?> Segun o/p N&ordm;<? echo $reg8[6] ?></td>
		      <td bordercolor="#000000"><? echo $reg8[7] ?></td>
		      <td colspan="5" bordercolor="#000000">&nbsp;</td>
                  
    </tr>
 <?
	$sql9=mysql_query("Select * from fondo where fondo='".$fondo."' AND ano='$ano'",$conexion);
	while ($reg9= mysql_fetch_array($sql9)){

?>
      <tr>
        <td colspan="4" align="right" bordercolor="#000000">&nbsp;<? echo $reg9[4] ?></td>
        <td align="center" bordercolor="#000000" class="Estilo13"><div align="right">

		      <?
			$total_cuenta += $reg9[5];
			$fon2= number_format($reg9[5],2,",",".");
			echo $fon2 ?>
		    </div></td>
     <?       // pagos
     /*se suman todos los valores que han sido pagados segun hayan sido anulados o no para posteriormente calcular el porcentaje de ejecución
      *
      */
	$pag=mysql_query("SELECT pago.fondo, pago.anulado, id_pago.cuenta, sum(id_pago.monto_s)  FROM pago, id_pago where pago.cod_p=id_pago.cod_p and pago.fondo='$fondo' and id_pago.cuenta='$reg9[3]' and pago.anulado!=1  group by id_pago.cuenta",$conexion);

	while ($pago= mysql_fetch_array($pag)) {
	//echo $pago[2];
	//echo "<br>";
	if ($pago[1]!=1){
	$sumsaldo=$pago[3];
	$saldo=$reg9[5]-$sumsaldo;
	if ($pago[2]==""){
	$sumsaldo=1;
	$saldo=$reg9[5]-$sumsaldo;
	    }
	    }
	 $sumsaldo2= number_format($sumsaldo,2,",",".");
	 $saldo2= number_format($saldo,2,",",".");

// pagos ?>
		      <td align="right" bordercolor="#000000">&nbsp;<? echo $sumsaldo2; ?></td>
		      <td align="right" bordercolor="#000000">&nbsp;<? echo $saldo2; ?></td>
		      <td align="right" bordercolor="#000000">&nbsp;
   <? $porcentaje=($sumsaldo*100)/$reg9[5];
	  $porcentaje1=number_format($porcentaje,2,",",".");
	  echo $porcentaje1.'%';?></td>
    </tr>
		 <? $sum_total += $sumsaldo;
		}} ?>
         <tr>
		      <td colspan="4" align="right" bordercolor="#000000">&nbsp;</td>
		      <td align="right" bordercolor="#000000" class="Estilo13">&nbsp;<?
			  $total_cuenta2= number_format($total_cuenta,2,",",".");
			  echo $total_cuenta2; ?></td>
		      <td align="right" bordercolor="#000000">&nbsp;<?
			  $sum_total2= number_format($sum_total,2,",",".");
			  echo $sum_total2; ?></td>
		      <td align="right" bordercolor="#000000">&nbsp;<?
			  $total = $total_cuenta-$sum_total;
			  $total2= number_format($total,2,",",".");
			  echo $total2; ?></td>
		      <td align="right" bordercolor="#000000">&nbsp;<?
			  $porcentaje2=($sum_total*100)/$total_cuenta;
	  		  $porcentaje3=number_format($porcentaje2,2,",",".");
	 		  echo $porcentaje3.'%';?></td>
    </tr>


</table>

<div align="center"> <a href="fondo0.php">Regresar </a></div>
</body>
</html>